﻿@model FairyWorld.Models.Fold

@{
    ViewBag.Title = "Files";
    Layout = "~/Views/Shared/GroupLayout.cshtml";
}

<script>
    $(document).ready(function () {
        $("#filesli").attr("class", "active");
    })
    function update(message) {
        $.post("/Group/Files", { "op": message },
        function (data) {
            var str = '<tr>' +
        '<th class="span1">类型</th>' +
        '<th class="span2">名称</th>' +
        '<th class="span2">操作</th>' +
        '<th class="span1">大小(kb)</th>' +
        '<th class="span1">上传时间</th>' +
        '<th class="span1">下载次数</th></tr>';
            for (item = 0; item < data.folds.length; ++item) {
                str += '<tr><td><img src="../../Content/image/icon/folder.png" style="width:30px"/>'
                + '</td><td><a onclick="update(\'+' + data.folds[item].foldname + '\')">' + data.folds[item].foldname + '</a></td>';
                if (document.getElementById("power").innerHTML == 2)
                    str += '<td><a onclick=\'deletef("' + data.folds[item].foldname + '",2)\'>删除</a></td>';
                else
                    str += "<td></td>";
                str += '<td></td><td></td><td></td></tr>';
            }
            for (item = 0; item < data.files.length; ++item) {
                    if (data.files[item].tag == 1) {
                        str += '<tr><td><img src="../../Content/image/icon/music.png" style="width:30px"/></td>';
                    } else if (data.files[item].tag == 2) {
                        str += '<tr><td><img src="../../Content/image/icon/image.png" style="width:30px"/></td>';
                    } else if (data.files[item].tag == 3 || data.files[item].tag == 4) {
                        var fname = data.files[item].filename;
                        var ex = fname.substr(fname.lastIndexOf(".") + 1, 3);
                        ex = ex.toLowerCase();
                        var type = "";
                        if (ex == "doc") {
                            type = "word";
                        }
                        else if (ex == "xls") {
                            type = "excel";
                        }
                        else {
                            type = ex;
                        }
                        str += '<tr><td><img src="../../Content/image/icon/' + type + '.png" style="width:30px"/></td>';
                    }
                    str += '<td>' + data.files[item].filename+'</td>';
                    if (document.getElementById("power").innerHTML == 2
                        || document.getElementById("user").innerHTML == data.files[item].creator.UserId)
                        str += '<td><a onclick=\'deletef("'
                        + data.files[item].filename + '",4)\'>删除</a>&nbsp;|&nbsp;';
                    else
                        str += '<td>';
                    str += '<a href="/Group/Download?name=' + data.files[item].filename + '&tag=4">下载</a>&nbsp;|&nbsp;' +
                           '<a href="/Group/FileDetail?name=' + data.files[item].filename + '&tag=4">下载记录</a></td>';
                    str += '<td>' + (data.files[item].size / 1024.0).toFixed(2) + '</td>'
                         + '<td>' + data.files[item].createTime + '</td>'
                         + '<td>' + data.files[item].hot + '</td>';
            }
            document.getElementById("content").innerHTML = str;
        });
    }
</script>

<style type="text/css">
        .textstyle1
        {
            color: Red;
            font-weight: bold;
        }
        .textstyle2
        {
            color: Green;
            font-weight: bold;
        }
	    .wrapper{ 
	    width:930px; 
	    background-color:#fff; 
	    position:relative;	    
	    box-shadow:1px 1px 4px rgba(0,0,0,0.4); 
	    -moz-box-shadow:1px 1px 4px rgba(0,0,0,0.4);
        -webkit-box-shadow: 1px 1px 4px rgba(0,0,0,.4);
        padding:20px;
	    }
 </style>

<h3>所有文件</h3>
<div class="wrapper">
<table id="content" class="table table-hover" style="font-family:'Arial Rounded MT', 'Microsoft YaHei'">
    <tr>
        <th class="span1">类型</th>
        <th class="span2">名称</th>
        <th class="span2">操作</th>
        <th class="span1">大小(kb)</th>
        <th class="span1">上传时间</th>
        <th class="span1">下载次数</th>
    </tr>
@foreach (var items in Model.folds)
{
    <tr>
            <td>
                <img src="../../Content/image/icon/folder.png" style="width:30px"/>
            </td>
            <td>
                <a onclick="update('+@items.foldname')">@items.foldname</a>
            </td>
            <td>
                @if (ViewBag.Power == 2)
                {
                    <a onclick='deletef("@items.foldname", 4)'>删除</a>
                }
            </td><td></td><td></td><td></td>
    </tr>
}
@foreach (var items in Model.files)
{
        <tr>
                @if(items.tag == 1)
                {<td>
                    <img src="../../Content/image/icon/music.png" style="width:30px"/>
                </td>}
                @if(items.tag == 2)
                {<td>
                    <img src="../../Content/image/icon/image.png" style="width:30px"/>
                </td>}
                @if(items.tag == 3 || items.tag == 4)
                {
                    var ex = items.filename.Substring(items.filename.LastIndexOf(".") + 1);
                    ex = ex.ToLower();
                    var type = "";
                    if (ex == "docx" || ex == "doc")
                    {
                        type = "word";
                    }
                    else if (ex == "xlsx" || ex == "xls")
                    {
                        type = "excel";
                    }
                    else if (ex == "ppt" || ex == "pptx")
                    {
                        type = "ppt";
                    }
                    else if (ex == "txt" || ex == "pdf" || ex == "zip" || ex == "rar")
                    {
                        type = ex;
                    }
                    else
                    {
                        type = "file";
                    }
                    var iconurl = "../../Content/image/icon/" + type + ".png";
                    <td>
                        <img src="@iconurl" style="width:30px"/>
                    </td>}
                <td>
                    @items.filename
                </td>
                <td>
                    @if (ViewBag.Power == 2 || ViewBag.User.UserId == items.creator.UserId)
                    {
                        <a onclick='deletef("@items.filename", 4)'>删除</a><span>&nbsp;|</span>   
                    }
                    @Html.ActionLink("下载", "Download", new { name = items.filename, tag = 4 })
                    |&nbsp;@Html.ActionLink("下载记录", "FileDetail", new { name = items.filename, tag = 4})
                </td>
            <td>@{var fsize = items.size / 1024.0; fsize = Math.Round(fsize, 2);} @fsize</td>
            <td>@items.createTime</td>
            <td>@items.hot</td>
        </tr>
}
</table>
<a onclick="update('-')">上一层</a>
@if (ViewBag.Power > 0)
{
    <div class="input-append" style="margin-top:10px">
        <input name="fold" id="newfold" type="text" placeholder="文件夹名"/>
        <input type="button" class="btn" onclick="addfolder()" value="新建文件夹"/>
        <input type="hidden" name="tag" id="tag" value="4" />
    </div>
    <div>
        <p>添加文件：</p>
        <p><input id="fileInput1" name="fileInput1" type="file"/></p>
        <p style="margin-top:5px;font-size:14px;font-weight:bold;">
        <a href="javascript:if(checkImport()){$('#fileInput1').uploadifySettings('scriptData',{'name':$('#test').val()});$('#fileInput1').uploadifyUpload();}">导入文件</a></p>
        <p style="margin-top:5px;font-size:14px;font-weight:bold;"><span id="result"></span></p>
    </div>
}
<div style="visibility:hidden" id="power">@ViewBag.Power</div>
<div style="visibility:hidden" id="user">@ViewBag.User.UserId</div>
</div>